<?php namespace Admin\Model;
use Hdphp\Model\Model;
class Goods extends Model{
    protected $table = "goods";
    protected $validate = array(
        array('category_cid','required','请选择所属分类',3,3),
        array('brand_bid','required','请选择所属品牌',3,3),
        array('gname','required','商品名称不能为空',3,3),
        array('unit','required','商品单位不能为空',3,3),
        array('market_price','required','市场价不能为空',3,3),
        array('shop_price','required','商城价不能为空',3,3),
        array('inventory','required','库存不能为空',3,3),
    );
    protected $auto = array(
        array('addtime','time','function',3,1)
    );
    //添加商品表
    public function store($data){
        if(!$this->create()) return false;
        $gid = $this->add($data);
        return $gid;
    }
    //删除
    public function del($gid){
        $this->where("gid={$gid}")->delete();
        $attrModel = new \Admin\Model\Goods_attr;
        $detailModel = new \Admin\Model\Goods_detail;
        $attrModel->where("goods_gid={$gid}")->delete();
        $detailModel->where("goods_gid={$gid}")->delete();
        return true;
    }
    //修改
    public function edit($gid){
        if(!$this->create()) return false;
        $this->where("gid={$gid}")->save();
        return true;
    }


}




?>